package com.hsp_java.collection_;

//import com.sun.org.apache.xpath.internal.objects.XObject;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class CollectionExercise {
    public static void main(String[] args) {
        //1.创建三个对象
        Collection col = new ArrayList();
        col.add(new Dog("布莱恩", 23));
        col.add(new Dog("布鲁斯", 3));
        col.add(new Dog("高菲", 5));

        //2.增强for遍历
        for (Object dog : col) {
            System.out.println(dog);
        }
        //3.while循环遍历
        //获得col的迭代器
        Iterator iterator = col.iterator();
        while (iterator.hasNext()) {
            Object next = iterator.next();
            System.out.println(next);
        }

    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}